package exam.bak.netease;

import java.util.Scanner;

public class P2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] params = scanner.nextLine().trim().split("\\s+");
        int m = Integer.parseInt(params[1]);
        System.out.println(solve(params[0], m));
    }

    // 必须使用m次
    public static int solve(String s, int m) {
        int total = 1;
        char[] chars = s.toCharArray();
        for (int i = 1; i < s.length(); i++) {
            if (useMagic(chars, i, m)) {
                total += 2 * m;
                i+=m-1;
            } else {
                total += distance(chars[i], chars[i - 1]);
                total += 1;
            }
        }

        return total;
    }

    public static boolean useMagic(char[] chars, int now, int m) {
        int total = 0;
        for (int i = now - 1; i < now + m-1; i++) {
            if(i>=chars.length-1){
                return false;
            }
            total += distance(chars[i], chars[i + 1]);
        }
        if (total > m) {
            return true;
        } else {
            return false;
        }
    }


    //寻找最小距离
    public static int distance(char a, char b) {
        int dis1 = Math.abs(b - a);
        int dis2 = 26 - dis1;
        return Math.min(dis1, dis2);
    }
}
